///**
// *
// */
//package com.dudu.interceptor;
//
//import com.alibaba.fastjson.JSONObject;
//import com.dudu.util.AccountUtil;
//import com.dudu.util.Const;
//import com.baijia.cas.ac.dto.AccountDto;
//import com.baijia.cas.ac.dto.RoleDto;
//import com.baijia.cas.client.api.facade.AccountApiFacade;
//import com.baijia.cas.client.util.AccessControlContext;
//import org.springframework.web.servlet.ModelAndView;
//import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.List;
//
///**
// * Created by dudu on 16/9/3.
// */
//public class LoginInterceptor extends HandlerInterceptorAdapter {
//
//	@Resource
//	private AccountApiFacade accountApiFacade;
//
//	@Override
//	public boolean preHandle(HttpServletRequest request,
//			HttpServletResponse response, Object handler) throws Exception {
//
//		if(AccessControlContext.getAccount() != null) {
//			AccountDto account = accountApiFacade.getAccount(AccessControlContext.getAccount().getId());
//			List<RoleDto> roleDtos = account.getHasRoles();
//			if(roleDtos.stream().anyMatch(roleDto -> roleDto.getAppId() == Const.APP_ID)) {
//				AccountUtil.setCurrentUser(account);
//			}else {
//				JSONObject resp = new JSONObject();
//				resp.put("code", Const.NO_AUTH);
//				response.setContentType("application/json; charset=utf-8");
//				response.setCharacterEncoding("utf-8");
//				response.getWriter().write(resp.toString());
//				return false;
//			}
//
//		}
//		return true;
//	}
//
//	@Override
//	public void postHandle(HttpServletRequest request,
//			HttpServletResponse response, Object handler,
//			ModelAndView modelAndView) throws Exception {
//		super.postHandle(request, response, handler, modelAndView);
//	}
//
//	@Override
//	public void afterCompletion(HttpServletRequest request,
//								HttpServletResponse response, Object handler, Exception ex)
//			throws Exception {
//
//		super.afterCompletion(request, response, handler, ex);
//	}
//
//}
